package jnpf.base.controller;

import io.swagger.annotations.ApiOperation;
import jnpf.base.ActionResult;
import jnpf.base.service.IBaseSerialNumberService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 流水号规则Controller
 *
 * @author ruoyi
 * @date 2023-02-16
 */
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/api/base/number" )
public class BaseSerialNumberController {

    private final IBaseSerialNumberService iBaseSerialNumberService;

    @ApiOperation(value = "根据单据前缀按日期生成流水号")
    @RequestMapping(value = "/take/{prefix}", method = RequestMethod.GET)
    public String getSerialNumber(@PathVariable String prefix) {
        return iBaseSerialNumberService.getSerialNumber(prefix);
    }

    @ApiOperation(value = "根据单据前缀生成流水号")
    @RequestMapping(value = "/takeAc/{prefix}/{length}", method = RequestMethod.GET)
    public ActionResult<String> getShortSerialNumberAc(@PathVariable String prefix, @PathVariable Integer length) {
        String serialNumber = iBaseSerialNumberService.getSerialNumber(prefix, length);
        return ActionResult.success(serialNumber);
    }

    @ApiOperation(value = "根据单据前缀生成流水号")
    @RequestMapping(value = "/take/{prefix}/{length}", method = RequestMethod.GET)
    public String getShortSerialNumber(@PathVariable String prefix, @PathVariable Integer length) {
        String serialNumber = iBaseSerialNumberService.getSerialNumber(prefix, length);
        return serialNumber;
    }




}
